<html>
<head><meta charset="utf-8"><title>repeatable arbitrary · general · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/index.html">general</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/repeatable.20arbitrary.html">repeatable arbitrary</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="154882789"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/repeatable%20arbitrary/near/154882789" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/repeatable.20arbitrary.html#154882789">(Jan 11 2019 at 00:08)</a>:</h4>
<p><span class="user-mention" data-user-id="126931">@centril</span> If I wanted to use <code>Arbitrary</code>outside of proptest to generate test data, how could I make it repeatable? For example, is there a way I can control the RNG and its seed?</p>



<a name="154882886"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/repeatable%20arbitrary/near/154882886" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> centril <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/repeatable.20arbitrary.html#154882886">(Jan 11 2019 at 00:11)</a>:</h4>
<p><span class="user-mention" data-user-id="116155">@Jake Goulding</span>  so what <code>Arbitrary::arbitrary</code> does is merely return a type that implements <code>Strategy</code>;  A strategy then defines how to generate a <code>ValueTree</code> (which defines how to shrink + produce values) <em>based</em> on a <code>TestRunner</code> that it gets as an argument to <code>new_tree</code>; what the <code>proptest! { .. }</code> macro does is the setup of the test runner and such behind the scenes</p>



<a name="154882895"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/repeatable%20arbitrary/near/154882895" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> centril <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/repeatable.20arbitrary.html#154882895">(Jan 11 2019 at 00:11)</a>:</h4>
<p><a href="https://altsysrq.github.io/rustdoc/proptest/latest/proptest/strategy/trait.Strategy.html#tymethod.new_tree" target="_blank" title="https://altsysrq.github.io/rustdoc/proptest/latest/proptest/strategy/trait.Strategy.html#tymethod.new_tree">https://altsysrq.github.io/rustdoc/proptest/latest/proptest/strategy/trait.Strategy.html#tymethod.new_tree</a></p>



<a name="154882940"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/repeatable%20arbitrary/near/154882940" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> centril <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/repeatable.20arbitrary.html#154882940">(Jan 11 2019 at 00:12)</a>:</h4>
<p><a href="https://altsysrq.github.io/rustdoc/proptest/latest/proptest/test_runner/struct.TestRunner.html" target="_blank" title="https://altsysrq.github.io/rustdoc/proptest/latest/proptest/test_runner/struct.TestRunner.html">https://altsysrq.github.io/rustdoc/proptest/latest/proptest/test_runner/struct.TestRunner.html</a></p>



<a name="154882952"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/repeatable%20arbitrary/near/154882952" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> centril <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/repeatable.20arbitrary.html#154882952">(Jan 11 2019 at 00:12)</a>:</h4>
<p>you can tweak the <code>Config</code> there for example</p>



<a name="154882958"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/repeatable%20arbitrary/near/154882958" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/repeatable.20arbitrary.html#154882958">(Jan 11 2019 at 00:12)</a>:</h4>
<blockquote>
<p>outside of proptest</p>
</blockquote>



<a name="154882972"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/repeatable%20arbitrary/near/154882972" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/repeatable.20arbitrary.html#154882972">(Jan 11 2019 at 00:13)</a>:</h4>
<p>i.e. the arbitrary crate (that is related, yeah?)</p>



<a name="154882981"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/repeatable%20arbitrary/near/154882981" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> centril <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/repeatable.20arbitrary.html#154882981">(Jan 11 2019 at 00:13)</a>:</h4>
<p><span class="user-mention" data-user-id="116155">@Jake Goulding</span>  no, that has nothing to do with proptest's version of Arbitrary</p>



<a name="154883027"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/repeatable%20arbitrary/near/154883027" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/repeatable.20arbitrary.html#154883027">(Jan 11 2019 at 00:14)</a>:</h4>
<p>that's unfortunate. Now I need to read different docs</p>



<a name="154883046"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/repeatable%20arbitrary/near/154883046" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/repeatable.20arbitrary.html#154883046">(Jan 11 2019 at 00:14)</a>:</h4>
<p>Maybe my question would then be... "is it useful to use proptest's <code>Arbitrary</code> to generate test data outside of directly used in proptest"</p>



<a name="154883060"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/repeatable%20arbitrary/near/154883060" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> centril <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/repeatable.20arbitrary.html#154883060">(Jan 11 2019 at 00:15)</a>:</h4>
<p>proptest and the quickcheck crate's model of property based testing differ entirely; proptest uses value based integrated shrinking and then uses Arbitrary to define canonical strategies for a type whereas the quickcheck crate uses type based shrinking</p>



<a name="154883067"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/repeatable%20arbitrary/near/154883067" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/repeatable.20arbitrary.html#154883067">(Jan 11 2019 at 00:15)</a>:</h4>
<p>I am aware of that, but I do not see how that relates to the topic at hand</p>



<a name="154883075"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/repeatable%20arbitrary/near/154883075" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> centril <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/repeatable.20arbitrary.html#154883075">(Jan 11 2019 at 00:15)</a>:</h4>
<p>hmm, lemme think about it a bit</p>



<a name="154883078"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/repeatable%20arbitrary/near/154883078" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/repeatable.20arbitrary.html#154883078">(Jan 11 2019 at 00:15)</a>:</h4>
<p>one step higher: I'd like to be able to generate 100MB of XML easily and test speed between my library and libxml</p>



<a name="154883123"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/repeatable%20arbitrary/near/154883123" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/repeatable.20arbitrary.html#154883123">(Jan 11 2019 at 00:16)</a>:</h4>
<p>I don't want to check in 100MB files</p>



<a name="154883127"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/repeatable%20arbitrary/near/154883127" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> centril <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/repeatable.20arbitrary.html#154883127">(Jan 11 2019 at 00:16)</a>:</h4>
<p><span class="user-mention" data-user-id="116155">@Jake Goulding</span>  you don't care about shrinking then?</p>



<a name="154883134"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/repeatable%20arbitrary/near/154883134" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/repeatable.20arbitrary.html#154883134">(Jan 11 2019 at 00:16)</a>:</h4>
<p>For that, no. But I <em>would</em> love to be able to reuse this code for actual proptesting</p>



<a name="154883137"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/repeatable%20arbitrary/near/154883137" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/repeatable.20arbitrary.html#154883137">(Jan 11 2019 at 00:16)</a>:</h4>
<p>where shrinking is much more useful</p>



<a name="154883148"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/repeatable%20arbitrary/near/154883148" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/repeatable.20arbitrary.html#154883148">(Jan 11 2019 at 00:17)</a>:</h4>
<p>For speed tests, I'd just want control over the "size"</p>



<a name="154883336"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/repeatable%20arbitrary/near/154883336" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> centril <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/repeatable.20arbitrary.html#154883336">(Jan 11 2019 at 00:20)</a>:</h4>
<p>OK; so outside of the definition of a Strategy, the only control over generation you have is the parameters you can set in <a href="https://altsysrq.github.io/rustdoc/proptest/latest/proptest/test_runner/struct.Config.html" target="_blank" title="https://altsysrq.github.io/rustdoc/proptest/latest/proptest/test_runner/struct.Config.html">https://altsysrq.github.io/rustdoc/proptest/latest/proptest/test_runner/struct.Config.html</a>, e.g. <code>cases: u32</code> -- if you want to just generate a bunch of <code>&lt;Foo as Strategy&gt;::Value</code> objects, then you can make a <code>TestRunner::new(my_config)</code>, instantiate your strategy, and then call <code>new_tree(the_runner).unwrap().current()</code> a bunch of times</p>



<a name="154883363"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/repeatable%20arbitrary/near/154883363" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> centril <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/repeatable.20arbitrary.html#154883363">(Jan 11 2019 at 00:21)</a>:</h4>
<p>current() should always give you the same thing, so <code>new_tree</code> is what you use to change the value generated</p>



<a name="154883432"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/repeatable%20arbitrary/near/154883432" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> centril <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/repeatable.20arbitrary.html#154883432">(Jan 11 2019 at 00:22)</a>:</h4>
<p>actually if you want to do this you don't need to touch <code>cases</code> at all since you are deciding how many to generate</p>



<a name="154883435"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/repeatable%20arbitrary/near/154883435" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> centril <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/repeatable.20arbitrary.html#154883435">(Jan 11 2019 at 00:22)</a>:</h4>
<p>might be useful to add a facility like this to proptest upstream</p>



<a name="154883450"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/repeatable%20arbitrary/near/154883450" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> centril <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/repeatable.20arbitrary.html#154883450">(Jan 11 2019 at 00:23)</a>:</h4>
<p>There will be some overhead cause proptest will include state that is only useful to shrinking</p>



<a name="154883461"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/repeatable%20arbitrary/near/154883461" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> centril <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/repeatable.20arbitrary.html#154883461">(Jan 11 2019 at 00:23)</a>:</h4>
<p>(but useless if you are not interested in shrinking)</p>



<a name="154883463"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/repeatable%20arbitrary/near/154883463" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> centril <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/repeatable.20arbitrary.html#154883463">(Jan 11 2019 at 00:23)</a>:</h4>
<p><span class="user-mention" data-user-id="116155">@Jake Goulding</span>  does that answer the question?</p>



<a name="154883672"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/repeatable%20arbitrary/near/154883672" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> centril <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/repeatable.20arbitrary.html#154883672">(Jan 11 2019 at 00:28)</a>:</h4>
<p>maybe it would be good to have <code>fn values&lt;S: Strategy&gt;(self, strat: S) -&gt; impl Iterator&lt;Item = S::Value&gt;</code> or something in <code>TestRunner</code></p>



<a name="154888863"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/repeatable%20arbitrary/near/154888863" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/repeatable.20arbitrary.html#154888863">(Jan 11 2019 at 02:29)</a>:</h4>
<p>It sounds like I should file an issue, to see if folk would find this or something similar useful</p>



<a name="154888908"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/repeatable%20arbitrary/near/154888908" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> centril <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/repeatable.20arbitrary.html#154888908">(Jan 11 2019 at 02:30)</a>:</h4>
<p><span class="user-mention" data-user-id="116155">@Jake Goulding</span>  yeah please do</p>



<a name="154888913"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/repeatable%20arbitrary/near/154888913" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> centril <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/repeatable.20arbitrary.html#154888913">(Jan 11 2019 at 02:30)</a>:</h4>
<p>(and cc me)</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>